package net;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

public class Receiver implements Runnable {

	private ServerSocket serverSocket;

	public Receiver() throws IOException {
		serverSocket = new ServerSocket(OlivawPortsServer.input);
	}

	@Override
	public void run() {
		while (true) {
			try {
				this._run();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}

	private void _run() throws IOException {
		Socket clientSocket = serverSocket.accept();
		System.out.println("Accepted");
		new Thread(new UserReceiver(clientSocket)).start();
		System.out.println("Started");
	}
	

	@Override
	protected void finalize() throws Throwable {
		serverSocket.close();
	}

}
